package app.cryp;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class AESCipher {

	private static final String AES_ALGORITHM = "AES/ECB/PKCS7Padding";

	public static byte[] decrypt(byte[] content, String password)
			throws Exception {

		SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");
		Cipher cipher = Cipher.getInstance(AES_ALGORITHM,
				BOUNCY_CASTLE_PROVIDER);// algorithmStr
		cipher.init(Cipher.DECRYPT_MODE, key);// ʼ
		byte[] result = cipher.doFinal(content);
		return result; //

	}
	public static final BouncyCastleProvider BOUNCY_CASTLE_PROVIDER = new BouncyCastleProvider();

	public static byte[] encrypt(String content, String password)
			throws Exception {
		
		SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");
		Cipher cipher = Cipher.getInstance(AES_ALGORITHM,
				BOUNCY_CASTLE_PROVIDER);
		cipher.init(Cipher.ENCRYPT_MODE, key);// ʼ
		byte[] result = cipher.doFinal(content.getBytes("utf-8"));
		return result; //

	}

}
